home *** CD-ROM | disk | FTP | other *** search
-
- ╔══════════════════════════════════════════╗
- ║ ║
- ║ A SIMPLE TEXT FILE LISTER ║
- ║ ║
- ║ ║
- ║ created by David Smith, because all the ║
- ║ file listers I found are written in ║
- ║ assembly language, and not in ║
- ║ "C". ║
- ║ ║
- ║ After all, us "C"ers need to stand up ║
- ║ for our heritage, huh ??? ║
- ║ ║
- ║ ║
- ║ QUESTIONS OR COMMENTS ?? ║
- ║ ║
- ║ DAVID SMITH ║
- ║ Compuserve 71441,2723 ║
- ║ ║
- ║ ║
- ╚══════════════════════════════════════════╝
-
- Bumped up in Turbo C++ April 7, 1991.
-
-
-
-
- #include <conio.h>
- #include <stdio.h>
- #include <dos.h>
-
- void other(void); /* functions */
- void minim(void);
- void maxim(void);
- void display(int start, int end);
-
- FILE *stream; /* variables we use */
- int i=1,j,max=0,c=3,t,b,x,y,a;
- long pos[200];
- char line[93],*file;
-
- void main(int argc, char *argv[])
- {
-
- _setcursortype(_NOCURSOR);
- strcpy(file,argv[1]);
-
- if((stream=fopen(argv[1],"rt"))==NULL) /* open file */
- {
- printf("Problems opening file");
- exit();
- }
- fseek(stream,0L,SEEK_SET);
-
- clrscr();
-
- do{ /* mark all lines of text with numbers */
- if(feof(stream)) break;
- pos[i]=ftell(stream);
- fgets(line,90,stream);
- i++;
- max++;
- } while(!feof(stream));
-
- b=j;
- display(1,25); /* set cursor position to top of text, then
- x=1; * call DISPLAY to print out 24 lines
- j=25; */
-
- other();
- }
-
-
- void other(void)
- {
-
- union REGS r; /* set up to call the screen scrolling function */
- r.h.ch=0;
- r.h.cl=0;
- r.h.dh=23;
- r.h.dl=79;
- r.h.bh=5;
- r.h.al=1;
-
- t=getch(); /* get user input */
-
- if(t==72){
- r.h.ah=7; /* call ROM BIOS to scroll up */
- int86(0x10,&r,&r);
- j--; /* decrease file pointer */
- x=j-24;
- if(x<1) minim();
- fseek(stream,pos[x],SEEK_SET); /* fill in blank space created by
- fgets(line,90,stream); * scrolling up
- gotoxy(1,1); */
- cprintf("%s",line);
- }
- if(t==80){
- gotoxy(1,25);
- r.h.ah=6; /* call ROM BIOS to scroll down */
- int86(0x10,&r,&r);
- j++;
- gotoxy(1,24);
- x=j-24;
- if(j>=max) maxim();
- fseek(stream,pos[j],SEEK_SET); /* fill in again */
- fgets(line,93,stream);
- cprintf("%s",line);
- }
- if(t==13) c++; /* increase color for text */
-
- if(t==81){
- clrscr(); /* if user wants a page to scroll, we move pointer
- j+=23; * down 23 lines, then call display to fill in
- gotoxy(1,24); */ the blanked screen
- x=j-24;
- if(j>=max) maxim();
- b=1;
- display(x,j);
- }
-
- if(t==73){ /* same with page up !! */
- clrscr();
- j-=23;
- x=j-24;
- if(x<1) minim();
- b=1;
- display(x,j);
- }
-
- if(c>15) c=1; /* if text color gets too high, bring it to ONE */
-
- if(t==27)
- {
- fcloseall();
- _setcursortype(_NORMALCURSOR); /* if ESC is entered, close up and
- exit(); * sign off for the day
- } */
- textcolor(c); /*recover the text color in case it was changed to red
- other(); because of an error (endoffile, beginningoffile) */
- }
-
- void display(int start, int end)
- {
- for(a=start;a<=end;a++) /* display 24 lines of text */
- {
- fseek(stream,pos[a],SEEK_SET);
- fgets(line,92,stream);
- gotoxy(1,b);
- cprintf("%s",line);
- b++;
- }
- }
-
- void minim(void) /* if beginning of file has been passed, clear screen
- { then goto position 1. Then, present beginfile message */
- x=1;
- j=25;
- clrscr();
- b=2;
- display(1,23);
- gotoxy(1,1);
- j-=3;
- textcolor(RED);
- cprintf(" *--* BEGINNING OF FILE *--* ");
- other();
- }
-
- void maxim(void)
- {
- j=max-1; /* do the same with end of file */
- x=j-24;
- clrscr();
- b=1;
- display(x,max);
- gotoxy(1,24);
- j +=2;
- textcolor(RED);
- cprintf(" *-* END OF FILE *-* ");
- other();
- }
-